var path = require("path");
const ffi = require('ffi-napi');
let dllPath = path.join(__dirname, "../../JsAdapter.dll");
let _service_lib = ffi.Library(dllPath, {
    'HwmJsCall': ["int", ["string"]],
    'HwmJsSetCallback': ['int', ["pointer"]],
});
let msgCallback = ffi.Callback("int", ["int","string"], function (cmd, msg) {
        console.log("get ret:",cmd,msg);
        let _data = {
            cmd,
            data:JSON.parse(msg)
        }
        global.remoteVars.win.webContents.send('nodeffiMsgCallback', _data);
    }
);

global.remoteVars.startHwmService = () => {
    _service_lib.HwmJsSetCallback(msgCallback);
};

global.remoteVars.sendServiceMsg = (cmdKey, cmd) => {
    return _service_lib.HwmJsCall(cmd);
};